package com.scu.phototabuser.util;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.test.espresso.core.deps.guava.base.Strings;

import static com.scu.phototabuser.util.Predictions.checkNotNull;

/**
 * Created by tianfei on 2017/4/9.
 */

public class FragmentUtil {


    /**
     *在container中加入一个Fragment
     * 只有设置了tag才会加入返回栈，加入后按下back会回到加入之前的状态
     *@Author tianff[tianff.scu@gmail.com]
     *@Date 2017/4/9
     *@return
     */
    public static void addFragmentToActivity (@NonNull FragmentManager fragmentManager,
                                              int frameId,
                                              @NonNull Fragment fragment,
                                              @Nullable String tag,
                                              boolean isAddToBackStack
                                              ) {
        checkNotNull(fragmentManager);
        checkNotNull(fragment);
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        transaction.replace(frameId,fragment,tag);

        if (isAddToBackStack){
            transaction.addToBackStack(tag);
        }

        transaction.commit();
    }


}
